﻿@Html.DevExpress().GridView(
settings =>
{
    
    settings.Name = "gridView";
    settings.InitDefaultPagerGridViewSettings();
    settings.EnableAlternatingRowColor();
    settings.CallbackRouteValues = new { Controller = "Account", Action = "ListPartialView" };

    settings.KeyFieldName = "account";
    settings.Columns.Add("name", "姓名");
    settings.Columns.Add("corpname", "所属单位");
    settings.Columns.Add("deptname","所属部门");
    
    settings.Columns.Add("account", "登陆ID");
    settings.Columns.Add("cn", "门户帐号");
    settings.Columns.Add("user_source", "用户来源");
    settings.Columns.Add("IsLoginEnable", "是否启用").ColumnType = MVCxGridViewColumnType.CheckBox;
    settings.Columns.Add("IsAdmin", "是否管理员").ColumnType = MVCxGridViewColumnType.CheckBox;
    bool permission = CurrentUser.CheckPermission(PermissionManager.编辑系统操作员);
    settings.Columns.Add(col =>
    {
        col.CellStyle.Paddings.Padding = 1;
        col.CellStyle.Paddings.PaddingLeft = 5;
        col.Caption = "";
        col.Width = 220;
        col.CellStyle.HorizontalAlign = HorizontalAlign.Center;

        col.SetDataItemTemplateContent(c =>
        {
            string userId = DataBinder.Eval(c.DataItem, "account").ToString();
            string user_source = DataBinder.Eval(c.DataItem, "user_source").ToString();
            if (permission)
            {
                ViewContext.Writer.Write(Html.ActionLink("[用户权限]", "UserPermissions", new { id = userId }));
                
                if (user_source == "原车管系统帐号")
                {
                    ViewContext.Writer.Write("&nbsp;");
                    ViewContext.Writer.Write(Html.ActionLink("[编辑用户]", "Edit", new { id = userId }));
                    ViewContext.Writer.Write("&nbsp;");
                    ViewContext.Writer.Write(Html.ActionLink("[重置密码]", "Reset", new { id = userId }, new { onclick = "return confirm('是否要重置此用户密码为111?')" }));
                    ViewContext.Writer.Write("&nbsp;");
                    
                    ViewContext.Writer.Write(Html.ActionLink("[删除]", "Delete", new { id = userId }, new { onclick = "return confirm('是否要删除此用户?')" }));
                }
            }
            else
            {
                ViewContext.Writer.Write("<a href='#' onclick = \"alert('你没有此权限。')\">[编辑权限]</a>");
            }
        }
        );
    });
}).BindEF((s, e) => {
        e.KeyExpression = "account";
        e.QueryableSource = this.GetUserList();
        e.DefaultSorting = "name asc";
    }).GetHtml()
